package com.itany.corejava.day02;

import java.io.UnsupportedEncodingException;
import java.util.Random;

public class Test2 {


    public static void main(String[] args) throws UnsupportedEncodingException {

        /*
            java内部没有byte，short
            当作int来处理
            为了c++程序员方便
            用byte，short不能提高性能
            也不能节省空间
         */
        byte b1=1;//int->byte

        byte b2= (byte) (b1+b1);//强制类型转换 int->byte

        byte b3=1+1;//JDK会做优化，编译时做计算 byte b3=2;

        int i=128;

        byte b4= (byte) i;


        // 0000 0000 0000 0000 0000 0000 1000 0000
        //1000 0000
        System.out.println("b4 = " + b4);

        byte b5=1;
        int i1=b5;//byte->int 自动类型转换

        long l=-1;//int->long 符号位扩展 正数补0，负数补1

        System.out.println("l = " + l);

        int max=0x7fffffff;
        int min=0x80000000;

        System.out.println("min = " + min);
        System.out.println("max = " + max);

        int i2=010;
        System.out.println("i2 = " + i2);

        // long l1=1024*1024*1024*2;
        // long l1=(long)(1024*1024*1024)*2;
        long l1=1024L*1024*1024*2;

        System.out.println("l1 = " + l1);


        double d=1;//int->double
        System.out.println("d = " + d);

        d=1.0;

        float f= (float) 1.2;
        f=1.2F;

        //double存储时不精确
        System.out.println("12.345-12 = " + (12.345 - 12));
        System.out.println("2.6-2 = " + (2.6-2));


        double d1=5.0/2;
        System.out.println("d1 = " + d1);



        char c='a';
        System.out.println("c = " + c);

        //java内部char当作int来处理
        System.out.println("c+1 = " + (c + 1));
        System.out.println("c+1 = " + (char)(c + 1));


        double n1=Math.random();//[0,1)之间的随机小数
        System.out.println("n1 = " + n1);

        Random random=new Random();
        int n2=random.nextInt(10);//[0,10)之间的随机整数

        //随机生成[a,b]之间的随机整数
        //[0,9]
        //Math.random() 0~0.9999999
        // Math.random()*10 //0~9.999999
        // (int)(Math.random()*10)+0 0~9

        //[2,11]
        // (int)(Math.random()*10)+2

        // (int)(Math.random()*(b-a+1))+a

        //随机生成a-z之间的字符
        char c1= (char) ((int)(Math.random()*('z'-'a'+1))+'a');
        System.out.println("c1 = " + c1);

        //将'5'转换成5
        char c2='5';
        //错
        // int i3=c2;
        int i3=c2-'0';
        System.out.println("i3 = " + i3);

        System.out.println((char)(5+'0'));

        char c3='中';
        System.out.println("c3 = " + c3);

        System.out.println("\"中\".getBytes(\"utf-8\").length = " + "中".getBytes("utf-8").length);

        char c4='\u4e2d';
        System.out.println("c4 = " + c4);

        boolean b=true;
        b=false;

    }


}
